{extend name='base' /}
{block name='content' /}
<!--tab标签-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">分值管理</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form layui-form-pane" action="{:url('admin/project/index')}" method="get">
                        <div class="layui-form-item">
                            <label class="layui-form-label">分类</label>
                            <div class="layui-input-inline">
                                <select name="cid" lay-verify="required" lay-search="">
                                    <option value="">选择分类或直接搜索选择</option>
                                    {foreach name="project_classify_level_list" item="vo"}
                                    <option value="{$vo.id}" {if condition="$cid==$vo.id"} selected="selected"{/if}>{neq name="vo.level" value="1"}|{php}for($i=1;$i<$vo['level'];$i++){echo ' ----';}{/php}{/neq} {$vo.title}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <label class="layui-form-label">关键词</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" value="{$keyword}" placeholder="请输入关键词" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">全部</option>
                                    <option value="2" {if condition="$status==2"} selected="selected"{/if}>当前显示</option>
                                    <option value="1" {if condition="$status==1"} selected="selected"{/if}>历史记录</option>
                                </select>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn">搜索</button>
                            </div>
                            <div class="layui-inline">
                                <a href="{:url('admin/project/index',['cleanup'=>'cleanup'])}" class="layui-btn layui-btn-danger">清除</a>
                                <a href="__UPLOAD__/moban/geshi.xlsx" class="layui-btn">模版下载</a>
                                <button type="button" class="layui-btn" id="import">
                                    <i class="layui-icon">&#xe67c;</i>导入数据
                                </button>
                            </div>
                        </div>
                    </form>
                    <hr>
                    <form class="layui-form" action="">
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th style="width: 30px;">ID</th>
                                <th>分类</th>
                                <th>名称</th>
                                <th>分值</th>
                                <th>状态</th>
                                <th style="width: 130px;">创建时间</th>
                                <th style="width: 120px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="project_list" item="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.project_classify}</td>
                                <td>{$vo.title}</td>
                                <td>{$vo.score}</td>
                                <td>
                                    {switch name="vo.status"}
                                    {case value="0"}历史记录{/case}
                                    {case value="1"}<font style="color: #ff0000;">当前显示</font>{/case}
                                    {default /}
                                    {/switch}
                                </td>
                                <td>{$vo.create_time}</td>
                                <td>
                                    <div class="layui-btn-group">
                                        <a href="{:url('admin/project/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-sm ajax-delete" title="删除"><i class="layui-icon">&#xe640;</i></a>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </form>
                    <!--分页-->
                    {$project->render()}
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['layer','form','layer','upload'], function(){ //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer,upload = layui.upload; //独立版的layer无需执行这一句
        var form = layui.form;

        /**
         * 数据导入
         */
        var uploadInst = upload.render({
            elem: "#import" //绑定元素
            ,url: "{:url('admin/project/import')}" //上传接口
            ,accept: 'file' //普通文件
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            ,done: function(res, index, upload){
                layer.closeAll('loading'); //关闭loading
                //页面层
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['500px', '500px'], //宽高
                    content: "<div style='padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;'>"+res.message+"</div>"
                });
            }
            ,error: function(index, upload){
                layer.closeAll('loading'); //关闭loading
            }
        });

        /**
         * 通用删除
         */
        $('.ajax-delete').on('click', function () {
            var _href = $(this).attr('href');
            layer.open({
                shade: false,
                content: '确定删除？',
                btn: ['确定', '取消'],
                yes: function (index) {
                    $.ajax({
                        url: _href,
                        type: "get",
                        success: function (info) {
                            if (info.code === 1) {
                                setTimeout(function () {
                                    location.href = info.url;
                                }, 1000);
                            }
                            layer.msg(info.msg);
                        }
                    });
                    layer.close(index);
                }
            });

            return false;
        });

    });
</script>
{/block}